import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;

public class GroupManagement {
    private static List<String> groups = new ArrayList<>(); // 存储小组的列表

    // 新增小组
    public void addGroup() {
        // 实现新增小组的逻辑
    }

    // 维护小组
    public void maintainGroup() {
        // 实现维护小组的逻辑
    }

    // 小组列表
    public void listGroups() {
        // 实现获取小组列表的逻辑
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> {
            createAndShowGUI();
        });
    }

    private static void createAndShowGUI() {
        JFrame frame = new JFrame("小组管理");
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frame.setSize(400, 300);

        JPanel panel = new JPanel();
        panel.setLayout(new GridLayout(0, 1));
        frame.getContentPane().add(panel);

        JLabel label = new JLabel("小组管理功能", JLabel.CENTER);
        panel.add(label);

        JButton addGroupButton = new JButton("新增小组");
        addGroupButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String groupName = JOptionPane.showInputDialog(frame, "请输入小组名称:");
                if (groupName != null && !groupName.trim().isEmpty()) {
                    groups.add(groupName);
                    JOptionPane.showMessageDialog(frame, "小组添加成功: " + groupName);
                } else {
                    JOptionPane.showMessageDialog(frame, "小组名称不能为空");
                }
            }
        });
        panel.add(addGroupButton);

        JButton maintainGroupButton = new JButton("维护小组");
        maintainGroupButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(frame, "维护小组功能尚未实现");
            }
        });
        panel.add(maintainGroupButton);

        JButton listGroupsButton = new JButton("小组列表");
        listGroupsButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                StringBuilder groupList = new StringBuilder();
                for (String g : groups) {
                    groupList.append(g).append("\n");
                }
                JOptionPane.showMessageDialog(frame, groupList.length() > 0 ? groupList.toString() : "没有小组");
            }
        });
        panel.add(listGroupsButton);

        frame.setVisible(true);
    }
}
